<?
include('adodb/adodb-exceptions.inc.php'); 
require ("comun/ini.php");
if(isset($_POST['JsonEnv'])){

	$JsonEnv = new Services_JSON();
	$JsonRec = new Services_JSON();
	$JsonRec=$JsonRec->decode(str_replace("\\","",$_POST['JsonEnv']));	
	try {
		$q = "SELECT actual FROM chequeras AS A WHERE id_cuenta=$JsonRec->Cuenta AND estatus='A' ORDER BY actual LIMIT 1";
		
		$r = $conn->Execute($q);
		$i=0;
		if(!$r->EOF){
			$q2 = "SELECT * FROM pagos_cxp_formas WHERE tipo_pago=3 AND id_cuenta = $JsonRec->Cuenta AND cheque = " . $r->fields['actual'] . " LIMIT 1";
			$r2 = $conn->Execute($q2);
			if (!$r2->EOF) {
				$Cheque[$i]['C'] = "";
				$Cheque[$i]['D'] = "CU";			
			} else {
				$Cheque[$i]['C'] = $r->fields['actual'];
				$Cheque[$i]['D'] = "OK";
			}
		} else {
			$Cheque[$i]['C'] = "";
			$Cheque[$i]['D'] = "NE";
		}
		if(is_array($Cheque)){
			echo $JsonEnv->encode($Cheque);
		}else{
			echo false;
		}
	}catch( ADODB_Exception $e ){
		//	echo ERROR_CATCH_GENERICO;
		echo false;
	}
}
?>